package com.sdgc.controller;

import com.sdgc.pojo.Dept;
import com.sdgc.pojo.Result;
import com.sdgc.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {
//    private static final Logger log = LoggerFactory.getLogger(DeptController.class);
    @Autowired
    private DeptService deptService;
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
//        System.out.println("查询部门ID为：" + id + "的部门详情");
        log.info("查询部门ID为：{}",id);
        Dept dept = deptService.getInfo(id);
        return Result.success(dept);
    }
    @GetMapping
    public Result list(){
//        System.out.println("查询全部的部门数据");
        log.info("查询全部的部门数据");
        List<Dept> deptList = deptService.findAll();
        return Result.success(deptList);
    }
    @DeleteMapping
    public Result DeleteById(Integer id){
//        System.out.println("根据部门ID删除部门数据：" + id);
        log.info("根据部门ID删除部门数据：{}",id);
        deptService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept){
//        System.out.println("新增部门：" + dept);
        log.info("新增部门：{}",dept);
        deptService.add(dept);
        return Result.success();
    }
//    @GetMapping("/{id}")
//    public Result getInfo(@PathVariable("id") Integer deptId){
//        System.out.println("查询部门ID为：" + deptId + "的部门详情");
////        Dept dept = deptService.getInfo(deptId);
//        return Result.success();
//    }

    @PutMapping
    public Result update(@RequestBody Dept dept){
//        System.out.println("修改部门, dept=" + dept);
        log.info("修改部门{}",dept);
        deptService.update(dept);
        return Result.success();
    }
}
